package com.olymtech.jbricks.dingtalk.message.delivery.request;

import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
import com.olymtech.jbricks.dingtalk.message.Message;
import com.olymtech.jbricks.dingtalk.message.delivery.msg.MessageFactory;
import com.olymtech.jbricks.dingtalk.message.delivery.msg.WorkMessageFactory;
import com.olymtech.jbricks.dingtalk.message.delivery.MessageDelivery;
import com.olymtech.jbricks.dingtalk.message.delivery.WorkMessageDelivery;
import com.taobao.api.BaseTaobaoRequest;

/**
 * @author haoting.wang
 * @date 2020/12/10 4:33 下午
 **/
public class WorkTaobaoRequest {

    private WorkMessageDelivery messageDelivery;

    private Message message;

    public WorkTaobaoRequest(MessageDelivery messageDelivery, Message message) {
        this.messageDelivery = (WorkMessageDelivery) messageDelivery;
        this.message = message;
    }

    public BaseTaobaoRequest build() {

        OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
        request.setAgentId(messageDelivery.getAgentId());
        if (messageDelivery.getUseridList() != null && messageDelivery.getUseridList().size() > 0) {
            request.setUseridList(String.join(",", messageDelivery.getUseridList()));
        }
        if (messageDelivery.getDeptIdList() != null && messageDelivery.getDeptIdList().size() > 0) {
            request.setDeptIdList(String.join(",", messageDelivery.getDeptIdList()));
        }
        request.setToAllUser(messageDelivery.isToAllUser());

        MessageFactory messageFactory = new WorkMessageFactory();

        request.setMsg((OapiMessageCorpconversationAsyncsendV2Request.Msg) messageFactory.conversationMessage(message));

        return request;
    }
}
